// pages/earthquake/earthquake.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData:[],
    markers:[],
  },

  onShow() {
    let that = this
    wx.authorize({
      scope:'scope.userLocation',
      success(res){
        wx.getLocation({
          success(res){
            that.setData({
              longitude:res.longitude,
              latitude:res.latitude
            })
          },
        })
      },
      fail(res){console.log(res,'拒绝授权')}
    })
    wx.request({
      url: 'https://cn.apihz.cn/api/tianqi/dizhen.php?id=10004623&key=305ae14c57cdced986290c166b5e3328',
      method:"GET",
      success: (res) => {
        if (res.statusCode === 200 && Array.isArray(res.data.data)) {
          const processedData = res.data.data
           const newList = processedData.map((item, index) =>
          index === 0? {...item, name: 'newName' } : item)
            this.setData({
             listData:newList,
              markers: newList.map(item => ({
              id:item.index,
              longitude: item.jingdu,
              latitude: item.weidu,
              name:item.weizhi,
              width:20,
              height:30
            }))
          })
          console.log("newList",newList)
          console.log("listData",this.data.listData)
        }
      }
    })
  },
})
